//============================================================================ //Gios Pdf.NET - A library for exporting Pdf Documents in C# //Copyright (C) 2005 Paolo Gios - www.paologios.com // //This library is free software; you can redistribute it and/or //modify it under the terms of the GNU Lesser General Public //License as published by the Free Software Foundation; either //version 2.1 of the License, or (at your option) any later version. // //This library is distributed in the hope that it will be useful, //but WITHOUT ANY WARRANTY; without even the implied warranty of //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU //Lesser General Public License for more details. // //You should have received a copy of the GNU Lesser General Public //License along with this library; if not, write to the Free Software //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //============================================================================= using System; using System.Data; using System.Collections; using System.Text; using System.Drawing; using System.IO; namespace HH.WMS.Utils.Gios.Pdf { /// /// the generic Pdf Table class. /// public class PdfTable :HH.WMS.Utils.Gios.Pdf.PdfCellRange { internal int columns,rows; internal Hashtable cells; internal PdfArea TableArea; internal PdfTable header=null; internal PdfDocument PdfDocument; internal int renderingIndex; internal int renderingRows; internal bool visibleHeaders=true; internal ArrayList pdfRows; internal ArrayList pdfColumns; /// /// gets or sets if table headers will be visible. /// public bool VisibleHeaders { get { return this.visibleHeaders; } set { this.visibleHeaders=value; } } /// /// returns the header of the the Table. It will be considered as a usual PdfRow. /// public PdfRow HeadersRow { get { return this.header.Rows[0]; } } private PdfRow[] _Rows; /// /// the Collection of the Rows of the Table. /// public PdfRow[] Rows { get { if (this._Rows==null) this._Rows=this.pdfRows.ToArray(typeof(PdfRow)) as PdfRow[]; return this._Rows; } } private PdfColumn[] _Columns; /// /// the Collection of the Columns of the Table. /// public PdfColumn[] Columns { get { if (this._Columns==null) this._Columns=this.pdfColumns.ToArray(typeof(PdfColumn)) as PdfColumn[]; return this._Columns; } } private double borderWidth; private Color borderColor; private BorderType borderType; /// /// sets the borders style of the Table. /// /// /// /// public void SetBorders(Color BorderColor,double BorderWidth,BorderType BorderType) { if (BorderWidth<=0) throw new Exception("BorderWidth must be grater than zero."); this.borderColor=BorderColor; this.borderType=BorderType; this.borderWidth=BorderWidth; if (this.header!=null) { this.header.borderColor=BorderColor; this.header.borderType=BorderType; this.header.borderWidth=BorderWidth; } } /// /// sets the widths of the Columns. /// /// public void SetColumnsWidth(int[] ColumnsWidthArray) { if (ColumnsWidthArray.Length>this.columns) throw new Exception("Table has only "+this.columns+" columns."); for (int index=0;index /// gets a Cell of the Table. /// /// /// /// public PdfCell Cell(int Row,int Column) { object o=this.cells[Row+","+Column]; if (o==null) throw new Exception("Cell ["+Row+","+Column+"] does not exist in the Table."); return o as PdfCell; } /// /// gets a range of Cells of the Table. /// /// /// /// /// /// public PdfCellRange CellRange(int startRow,int startColumn,int endRow,int endColumn) { return new PdfCellRange(this,startRow,startColumn,endRow,endColumn); } internal PdfTable(PdfDocument PdfDocument,ContentAlignment DefaultContentAlignment,Font Font,Color DefaultForegroundColor,int Rows ,int Columns,double CellPadding) { cells=new Hashtable(); pdfRows=new ArrayList(); this.owner=this; this.PdfDocument=PdfDocument; this.borderWidth=0; this.pdfColumns=new ArrayList(); this.rows=Rows; this.startRow=0; this.startColumn=0; this.endColumn=Columns-1; this.endRow=Rows-1; this.columns=Columns; for (int c=0;c /// sets the Height of the Rows of the Table. We suggest you not to use it /// unless each rows contains more or less the same quantity of Text. /// /// public void SetRowHeight(double RowHeight) { if (RowHeight<=0) throw new Exception("Row Height must be grater than zero."); foreach (PdfRow pr in this.Rows) pr.SetRowHeight(RowHeight); } /// /// Imports text from a datatable. /// /// The Source Datatable /// the starting row of the Pdf Table that will import datas. /// the starting column of the Pdf Table that will import datas. /// the starting row of the DataTable that will export datas. /// the ending row of the DataTable that will export datas. public void ImportDataTable(DataTable dt,int PdfTableStartRow,int PdfTableStartColumn, int DataTableStartRow,int DataTableEndRow) { for (int r=DataTableStartRow;((r=0&&c+PdfTableStartColumn=0&&c+PdfTableStartColumn /// Imports text from a datatable. /// /// The Source Datatable /// the starting row of the Pdf Table that will import datas. /// the starting column of the Pdf Table that will import datas. public void ImportDataTable(DataTable dt,int PdfTableStartRow,int PdfTableStartColumn) { ImportDataTable(dt,PdfTableStartRow,PdfTableStartColumn,0,999999); } /// /// Imports text from a datatable. /// /// The Source Datatable public void ImportDataTable(DataTable dt) { ImportDataTable(dt,0,0,0,999999); } /// /// returns true if all the pages of the Table are already rasterized to a TablePage. /// public bool AllTablePagesCreated { get { if (this.renderingIndex+this.renderingRows>this.rows-1) return true; return false; } } /// /// Creates the TablePage, the rasterized page of a Table. /// /// /// public PdfTablePage CreateTablePage(PdfArea PageArea) { this.TableArea=PageArea.Clone(); PdfTablePage ptp; if (!this.visibleHeaders) ptp=this.createTablePage(); else { this.header.TableArea=PageArea.Clone(); this.header.TableArea.height=this.HeadersRow.Height; this.TableArea.posy+=this.HeadersRow.Height; this.TableArea.height-=this.HeadersRow.Height; ptp=this.createTablePage(); ptp.stream+=this.header.createTablePage().stream; this.header.renderingIndex=0; } foreach (PdfColumn pc in this.Columns) pc.CompensatedWidth=-1; foreach (PdfColumn pc in this.header.Columns) pc.CompensatedWidth=-1; return ptp; } internal PdfTablePage createTablePage() { int index=this.renderingIndex; double h=this.Rows[index].Height; double oh=0; while ((h<=this.TableArea.height)&&(index0) { sb.Append(new PdfRectangle(this.PdfDocument,new PdfArea(this.PdfDocument,0,0,1,1),this.borderColor ,this.borderWidth).ToColorAndWidthStream()); int bt=(int)this.borderType; if ((bt==1)||(bt==3)||(bt==5)||(bt==6)) sb.Append(this.TableArea.ToRectangle(this.borderColor,this.borderWidth).ToRectangleStream()); for (int rowIndex=this.renderingIndex;(rowIndex